﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;

namespace WarOfDev.Web.Controllers
{
    public class ImagesController : BaseController
    {
        //
        // GET: /Images/

        public ActionResult Index()
        {
            return View();
        }

        public  FileResult GetImage(string id)
        {
            string path = Path.Combine(Server.MapPath("/Content/Files/testFiles"), id);
                if (System.IO.File.Exists(path))
                {
                    return base.File(path, GetContentType(path));
                }
                return null;
        
        }

        string GetContentType(string filename)
        {
            FileInfo file = new FileInfo(filename);
            switch (file.Extension.ToUpper())
            {
                case ".PNG": return "image/png";
                case ".JPG": return "image/jpeg";
                case ".JPEG": return "image/jpeg";
                case ".GIF": return "image/gif";
                case ".BMP": return "image/bmp";
                case ".TIFF": return "image/tiff";
                default: throw new NotSupportedException("文件类型不支持.");
            }
        }

    }
}
